Visualizing `&&`, `||`, and `??` with short-circuiting.
These operators evaluate from left to right. They are **short-circuiting**, meaning the second operand is only evaluated if necessary.
"" && "world"; // "" "hello" && "world"; // "world" null || "default"; // "default" "hello" || "world"; // "hello"
Expression:
Result:
Expression:
Result:
The **Nullish Coalescing** operator returns the right-hand side operand only if the left-hand side operand is either **`null` or `undefined`**. It does not consider other falsy values like `0` or `''` as invalid, making it a safer alternative to `||` for providing default values.
0 ?? 10; // 0 '' ?? "default"; // "" null ?? "default"; // "default"
Expression:
Result: